<?php
/**
 *
 * User: 梁晓伟  lxw11109@gmail.com
 * Date: 2017-09-05
 * Time: 17:06
 */

namespace App\Http\Controllers\Api\V1\Manager\Mall;


use App\Http\Controllers\Controller;
use App\Models\Banner;
use App\Models\Commodity;
use App\Models\CommodityComment;
use App\Models\CommoditySku;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class CommodityController extends Controller
{
    public function index(Request $request)
    {
        $data = Commodity::find(1);
        $data['goodPrice'] = $data['goodPrice'] / 100;
        return $this->apiResponse($data);
    }


    public function store(Request $request)
    {

        $data = $request->all();
        $validator = Validator::make($data, [
            'goodId' => 'required',
            'goodImage' => 'required',
            'goodTitle' => 'required',
        ]);
        if ($validator->fails()) {
            return $this->apiResponse('', config('errorCode.INVALID_REQ_PARAMS'));
        }
        $data['goodPrice'] = $data['goodPrice']  * 100;
        Commodity::where('goodId',$data['goodId'])->update($data);
        return $this->apiResponse(true);
    }

}